package com.tencent.iov.cowin.befsale.clue.controller.cus;

import com.tencent.iov.cowin.befsale.clue.controller.cus.assembler.CustomerBehaviorAssembler;
import com.tencent.iov.cowin.befsale.clue.controller.cus.vo.request.AddCustomerBehaviorRequest;
import com.tencent.iov.cowin.befsale.clue.controller.cus.vo.request.DeleteCustomerBehaviorRequest;
import com.tencent.iov.cowin.befsale.clue.controller.cus.vo.request.QueryCustomerBehaviorRequest;
import com.tencent.iov.cowin.befsale.clue.controller.cus.vo.request.UpdateCustomerBehaviorRequest;
import com.tencent.iov.cowin.befsale.clue.controller.cus.vo.response.CustomerBehaviorResponse;
import com.tencent.iov.cowin.befsale.clue.domain.cus.po.CustomerBehavior;
import com.tencent.iov.cowin.befsale.clue.service.cus.CustomerBehaviorService;
import com.software.boot.common.entity.Response;
import com.software.boot.common.model.dao.PageRequest;
import com.software.boot.common.model.dao.PageResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @Describe: 客户行为标签统计表（线索中心需求建表）_Controller层
 * @author: xiamu
 * @created: 2022-01-11 16:00:54
 * @version: 1.0
 */
@RestController
@RequestMapping(value = "/v1/befsale/customerBehavior", produces = MediaType.APPLICATION_JSON_VALUE)
@Api(tags = "客户行为标签统计表（线索中心需求建表）_Controller层")
public class CustomerBehaviorController {

    @Autowired
    private CustomerBehaviorService customerBehaviorService;

    /**
     * 通过ID获取详细信息
     *
     * @param: id 主键ID
     * @return: CustomerBehavior对象
     */
    @ApiOperation(value = "CustomerBehavior管理-通过ID获取详细信息接口", httpMethod = "GET", response = Response.class, notes = "get_detail_by_id")
    @RequestMapping(path = "/get_detail_by_id", method = RequestMethod.GET)
    public Response<CustomerBehaviorResponse> getDetailById(@ApiParam(required = true, value = "对象ID", defaultValue = "1") @RequestParam("id") Long id) {
        return Response.success(CustomerBehaviorAssembler.transformPOToResponseVo(customerBehaviorService.getDetailById(id), CustomerBehaviorResponse.class));
    }

    /**
     * 单条数据插入CustomerBehavior
     *
     * @param request 参数
     * @return 插入的条数
     */
    @ApiOperation(value = "CustomerBehavior管理-添加信息接口", httpMethod = "POST", response = Response.class, notes = "add")
    @RequestMapping(path = "/add", method = RequestMethod.POST)
    public Response<Integer> add(@Valid @RequestBody AddCustomerBehaviorRequest request) {
        return Response.success(customerBehaviorService.insert(CustomerBehaviorAssembler.transformVOToPO(request, CustomerBehavior.class)));
    }

    /**
     * 批量插入CustomerBehavior
     *
     * @param requests 参数
     * @return 批量插入的条数
     */
    @ApiOperation(value = "CustomerBehavior管理-批量插入CustomerBehavior接口", httpMethod = "POST", response = Response.class, notes = "add_batch")
    @RequestMapping(path = "/add_batch", method = RequestMethod.POST)
    public Response<Integer> addBatch(@Valid @RequestBody List<QueryCustomerBehaviorRequest> requests) {
        return Response.success(customerBehaviorService.insertBatch(CustomerBehaviorAssembler.transformPOToResponseVoList(requests, CustomerBehavior.class)));
    }

    /**
     * 通过ID修改信息接口
     *
     * @param: request 参数
     * @return: 修改的条数
     */
    @ApiOperation(value = "CustomerBehavior管理-修改信息接口", httpMethod = "POST", response = Response.class, notes = "update")
    @RequestMapping(path = "/update", method = RequestMethod.POST)
    public Response<Integer> update(@Valid @RequestBody UpdateCustomerBehaviorRequest request) {
        return Response.success(customerBehaviorService.update(CustomerBehaviorAssembler.transformVOToPO(request, CustomerBehavior.class)));
    }

    /**
     * 通过ID删除数据
     *
     * @param request 参数
     * @return 删除的条数
     */
    @ApiOperation(value = "CustomerBehavior管理-通过ID删除接口", httpMethod = "POST", response = Response.class, notes = "delete")
    @RequestMapping(path = "/delete", method = RequestMethod.POST)
    public Response<Integer> delete(@Valid @RequestBody DeleteCustomerBehaviorRequest request) {
        return Response.success(customerBehaviorService.delete(CustomerBehaviorAssembler.transformVOToPO(request, CustomerBehavior.class)));
    }

    /**
     * 根据条件查询对象list列表
     *
     * @param request 参数
     * @return 查询结果
     */
    @ApiOperation(value = "CustomerBehavior管理-根据条件查询对象list列表接口", httpMethod = "POST", response = Response.class, notes = "query_list_by_param")
    @RequestMapping(path = "/get_list_by_param", method = RequestMethod.POST)
    public Response<List<CustomerBehaviorResponse>> getListByParam(@RequestBody QueryCustomerBehaviorRequest request) {
        List<CustomerBehavior> responseList = customerBehaviorService.getListByParam(CustomerBehaviorAssembler.transformVOToPO(request, CustomerBehavior.class));
        return Response.success(CustomerBehaviorAssembler.transformPOToResponseVoList(responseList, CustomerBehaviorResponse.class));
    }

    /**
     * 根据条件查询对象Page记录
     *
     * @param request 参数
     * @return 查询结果
     */
    @ApiOperation(value = "CustomerBehavior管理-根据条件查询对象Page记录接口", httpMethod = "POST", response = Response.class, notes = "get_page_by_param")
    @RequestMapping(value = "/get_page_by_param", method = RequestMethod.POST)
    public Response<PageResponse<CustomerBehaviorResponse>> getPageByParam(@RequestBody PageRequest<QueryCustomerBehaviorRequest> request) {
        PageResponse<CustomerBehavior> customerBehaviorPageResponse = customerBehaviorService.getPageByParam(CustomerBehaviorAssembler.transformVOToPOPage(request, CustomerBehavior.class));
        return Response.success(CustomerBehaviorAssembler.transformPOToResponseVoPage(customerBehaviorPageResponse, CustomerBehaviorResponse.class));
    }

    /**
     * 根据条件查询单个对象
     *
     * @param request 参数
     * @return 查询结果
     */
    @ApiOperation(value = "CustomerBehavior管理-根据条件查询单个对象接口", httpMethod = "POST", response = Response.class, notes = "get_page_by_param")
    @RequestMapping(value = "/get_one_by_param", method = RequestMethod.POST)
    public Response<CustomerBehaviorResponse> getOneByParam(@RequestBody QueryCustomerBehaviorRequest request) {
        CustomerBehavior customerBehavior = customerBehaviorService.getOneByParam(CustomerBehaviorAssembler.transformVOToPO(request, CustomerBehavior.class));
        return Response.success(CustomerBehaviorAssembler.transformPOToResponseVo(customerBehavior, CustomerBehaviorResponse.class));
    }

    /**
     * 按天统计客户行为信息
     *
     * @param startDate 开始统计日期
     * @param endDate 结束统计日期
     * @return 是否统计成功
     */
    @ApiOperation(value = "CustomerBehavior管理-统计客户行为信息", httpMethod = "GET", response = Response.class, notes = "statistical_customer_behavior")
    @GetMapping(value = "/statistical_customer_behavior")
    public Response<Boolean> statisticalCustomerBehavior(@ApiParam(required = false, value = "开始统计日期", defaultValue = "yyyy-MM-dd")  @RequestParam(value = "startDate", required = false) String startDate,
                                                    @ApiParam(required = false, value = "结束统计日期", defaultValue = "yyyy-MM-dd")  @RequestParam(value = "endDate", required = false) String endDate) {
        return Response.success(customerBehaviorService.statisticalCustomerBehavior(startDate, endDate));
    }
}